//
//  webService.m
//  APJ Resource
//
//  Created by Richard Zhao on 1/27/14.
//  Copyright (c) 2014 APJ. All rights reserved.
//

#import "webService.h"
#import "ServiceHelper.h"

@implementation webService

+ (BOOL)loginAccount:(NSString *)uid withPassword:(NSString *)pwd
{
    NSMutableArray *param = [NSMutableArray array];
    [param addObject:[NSDictionary dictionaryWithObjectsAndKeys:uid, @"account", nil]];
    [param addObject:[NSDictionary dictionaryWithObjectsAndKeys:pwd, @"password", nil]];
    
    ServiceHelper *wsHelper = [[ServiceHelper alloc] init];
    ServiceArgs *args = [[ServiceArgs alloc] init];
    [args setMethodName:@"login"];
    [args setSoapParams:param];
    ServiceResult *result = [wsHelper syncService:args];
//    NSLog(@"%@", [result xmlString]);
    return YES;
}

+(id)updateUserTable:(NSString *)dateFormateString
{
    NSMutableArray *param = [NSMutableArray array];
    [param addObject:[NSDictionary dictionaryWithObjectsAndKeys:dateFormateString, @"startTime", nil]];
    
    ServiceHelper *wsHelper = [[ServiceHelper alloc] init];
    ServiceArgs *args = [[ServiceArgs alloc] init];
    [args setMethodName:@"getUserTable"];
    [args setSoapParams:param];
    ServiceResult *result = [wsHelper syncService:args];
//    NSLog(@"%@", [result xmlString]);
    id json = [result json];
//    NSLog(@"%@", json);
    return json;
}

+ (id)pullUpdatedDataFromTable:(NSString *)table withColumns:(NSString *)columns startFrom:(NSString *)dateFormateString
{
    NSMutableArray *param = [NSMutableArray array];
    [param addObject:[NSDictionary dictionaryWithObjectsAndKeys:table, @"tableName", nil]];
    [param addObject:[NSDictionary dictionaryWithObjectsAndKeys:columns, @"columns", nil]];
    [param addObject:[NSDictionary dictionaryWithObjectsAndKeys:dateFormateString, @"startTime", nil]];
    
    ServiceHelper *wsHelper = [[ServiceHelper alloc] init];
    ServiceArgs *args = [[ServiceArgs alloc] init];
    [args setMethodName:@"getTable"];
    [args setSoapParams:param];
    ServiceResult *result = [wsHelper syncService:args];
    //NSLog(@"%@", [result xmlString]);
    id json = [result json];
    //NSLog(@"%@", json);
    return json;
}

+ (id)actionLogForTable:(NSString *)table startFrom:(NSString *)dateFormateString
{
    NSMutableArray *param = [NSMutableArray array];
    [param addObject:[NSDictionary dictionaryWithObjectsAndKeys:table, @"tableName", nil]];
    [param addObject:[NSDictionary dictionaryWithObjectsAndKeys:dateFormateString, @"startTime", nil]];
    
    ServiceHelper *wsHelper = [[ServiceHelper alloc] init];
    ServiceArgs *args = [[ServiceArgs alloc] init];
    [args setMethodName:@"syncTableFromActionLog"];
    [args setSoapParams:param];
    ServiceResult *result = [wsHelper syncService:args];
    //NSLog(@"%@", [result xmlString]);
    id json = [result json];
    //NSLog(@"%@", json);
    return json;
}

+ (id)downloadFileSince:(NSString *)lastSyncTime
{
    NSMutableArray *param = [NSMutableArray array];
    [param addObject:[NSDictionary dictionaryWithObjectsAndKeys:lastSyncTime, @"lastSyncTime", nil]];
    ServiceHelper *wsHelper = [[ServiceHelper alloc] init];
    ServiceArgs *args = [[ServiceArgs alloc] init];
    [args setMethodName:@"getUpdatedPhotos"];
    [args setSoapParams:param];
    ServiceResult *result = [wsHelper syncService:args];
    //NSLog(@"%@", [result binData]);
    id returnData = [result binData];
    return returnData;
}

@end
